<template>
  <div class="trends3-doctor-list-2" data-number="武德二年">
    <div class="queue-info" v-for="(itemInfo, key) in doctorDataClean">
      <div class="dept-room-default" :class="getClassName" :key="key">
        <template v-if="optionsInfo.wrapShow">
          <template v-for="(item) in itemInfo">
            <div class="room">
              <div class="line"><ScrollX>{{ getRoomDeptInfo.roomName || '\u00a0'  }}</ScrollX></div>
              <div class="line">
                <ScrollX>({{ item.deptName || getRoomDeptInfo.deptName || '\u00a0' }})</ScrollX>
              </div>
            </div>
          </template>
        </template>
        <template v-else>
          <p class="room">
            <template v-for="(item) in itemInfo">
              <ScrollX>
                {{ getRoomDeptInfo.roomName || '\u00a0'  }}
                ({{ item.deptName || getRoomDeptInfo.deptName || '\u00a0' }})
              </ScrollX>
            </template>
          </p>
        </template>
      </div>
      <div class="first-group flex-box" :key="key">
        <template v-for="(item) in itemInfo">
          <div class="left flex-left">
            <div class="left-img">
              <img :src="getDoctorPicture(item)" alt="医生" @error='handleError'/>
            </div>
            <div class="doc-area">
              <div class="name">
                <ScrollX>{{ item.workerName || '\u00a0' }}</ScrollX>
              </div>
              <div class="academic—title">
                <ScrollX>{{ item.workerTitle || '\u00a0' }}</ScrollX>
              </div>
            </div>
          </div>
          <div class="right flex-right">
            <div class="patient-wrap">
              <div class="item current-patient flex-box"
                   :class="getPatientClassName('current-patient',item)">
                <div class="title flex-box-left">{{ optionsInfo['currentPatientSign'] || '就诊' }}</div>
                <div class="content flex-box-right" :class="{'current-patient-info': scrollInfo(item)}">
                  <div class="scroll-info" v-if="scrollInfo(item)">
                    <vue-seamless-scroll
                        class="scroll"
                        :ref="`scroll-${item.workerId}`"
                        @ScrollEnd="(e)=>handleScrollEnd(e, item)"
                        :class-option="optionScroll2"
                        :data="(item.treatingPatient)"
                    >
                      <template v-for="PatientItem in (item.treatingPatient)">
                        <p class="item">
                          {{ (PatientItem.orderNo) || '\u00a0' }}
                          {{ (PatientItem.patientName) || '\u00a0' }}
                        </p>
                      </template>
                    </vue-seamless-scroll>
                  </div>
                  <p class="no-scroll-info" v-else>
                    <template v-for="PatientItem in (item.treatingPatient)">
                      {{ (PatientItem.orderNo) || '\u00a0' }}
                      {{ (PatientItem.patientName) || '\u00a0' }}
                    </template>
                  </p>
                </div>
              </div>
              <div class="item wait-patient flex-box"
                   :class="getPatientClassName('wait-patient',item)">
                <div class="title flex-box-left">{{ optionsInfo['waitPatientSign'] || '候诊' }}</div>
                <template v-if="waitPatientTypeInfo ===1">
                  <div class="content flex-box-right">
                    <p v-for="(item2,index) in getWaitingPatientList(item.waitingPatientList)"
                       :key="`${item2.patientIdNo}-${index}`">
                      {{ item2.orderNo || '\u00a0' }} {{ item2.patientName || '\u00a0' }}
                    </p>
                  </div>
                </template>
                <template v-else-if="waitPatientTypeInfo ===2">
                  <div class="content flex-box-right scroll-area"
                       :class="{'scroll-area-all': getWaitingPatientList(item.waitingPatientList).length>4 }">
                    <template
                        v-if="(optionsInfo.openScroll)&&(optionsInfo.waitPatientNumber)>(optionsInfo.waitPatientScrollNumber)">
                      <vue-seamless-scroll
                          class="scroll"
                          :ref="`scroll-${item.workerId}`"
                          @ScrollEnd="(e)=>handleScrollEnd(e, item)"
                          :class-option="optionScroll"
                          :data="getWaitingPatientList(item.waitingPatientList)"
                      >
                        <div class="inside-content" :class="getWaitPatientNumber((item.waitingPatientList), true)">
                          <div class="patient"
                               v-for="(item2,index) in getWaitingPatientList(item.waitingPatientList)"
                               :key="`${(item2.queuingId) || index}-${(item2.patientIdNo) || index}`"
                          >
                            <span class="patient-orderNo" v-if="!!(item2.orderNo)">
                              {{ item2.orderNo || '\u00a0'}}
                            </span>
                            <template>
                              {{ item2.patientName || '\u00a0' }}
                            </template>
                          </div>
                        </div>
                      </vue-seamless-scroll>
                    </template>
                    <template v-else>
                      <div class="no-scroll-area" :class="getWaitPatientNumber((item.waitingPatientList), false)">
                        <p v-for="(item2,index) in getWaitingPatientList(item.waitingPatientList)"
                           :key="`${item2.patientIdNo}-${index}`">
                          {{ item2.orderNo || '\u00a0' }} {{ item2.patientName || '\u00a0' }}
                        </p>
                      </div>
                    </template>
                  </div>
                </template>
              </div>
              <div class="item pass-patient flex-box"
                   :class="getPatientClassName('pass-patient',item)">
                <div class="title flex-box-left">过号</div>
                <div class="content flex-box-right"
                     :class="{'current-patient-info': scrollInfoOver(item)}"
                >
                  <div class="scroll-info" v-if="scrollInfoOver(item)">
                    <vue-seamless-scroll
                        class="scroll2"
                        :ref="`scroll-${item.workerId}`"
                        @ScrollEnd="(e)=>handleScrollEnd(e, item)"
                        :class-option="optionScroll2"
                        :data="(item.overPatientList)"
                    >
                      <div class="inside-content ">
                        <div class="patient"
                             v-for="(item2,index) in item.overPatientList"
                             :key="`${(item2.queuingId) || index}-${(item2.patientIdNo) || index}`"
                        >
                          <span class="patient-orderNo" v-if="!!(item2.orderNo)">
                            {{ item2.orderNo }}
                          </span>
                          <template>
                            {{ item2.patientName || '' }}
                          </template>
                        </div>
                      </div>
                    </vue-seamless-scroll>
                  </div>
                  <div class="no-scroll-info2" v-else>
                    <template v-for="item2 in (item.overPatientList)">
                      <div>{{ item2.orderNo || '\u00a0' }} {{ item2.patientName || '\u00a0' }}</div>
                    </template>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import {v4 as uuid} from 'uuid';
import vueSeamlessScroll from 'vue-seamless-scroll';
import ScrollX from '@c/public/seamlessScroll/ScrollX.vue';
import ScrollY from "@c/public/seamlessScroll/ScrollY.vue";
import {pxToVw} from "@/utils/common";
import Template from "@sc/template/index.vue";
import Header from "@c/layout/modules/header/index.vue";
export default {
  name: "trends3DoctorList-2",

  componentName: "trends3DoctorList2",

  components: {
    Header,
    Template,
    ScrollX,
    ScrollY,
    vueSeamlessScroll
  },

  props: {
    devType: {
      type: Boolean,
      default: false,
    },
    field: {
      type: Object,
      default: Object(),
    },
    doctorData: {
      type: Array,
      default: Array(),
    }
  },

  data() {
    return {
      status: true,
      widgetKey: uuid(),
      optionsInfo: Object(),
      header: require("@a/images/design/header.jpeg"),
      pause: require("@a/images/design/pause.png"),
    }
  },

  computed: {
    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'head':
            Reflect.set(Obj, 'height', pxToVw(info.headHeight));
            Reflect.set(Obj, 'backgroundColor', `${(info.backgroundColor)}`);
            return Obj;
          case 'picture':
            Reflect.set(Obj, 'height', pxToVw(info.imageHeight));
            Reflect.set(Obj, 'width', pxToVw(info.imageWidth));
            Reflect.set(Obj, 'borderRadius', pxToVw(info.imageRadius));
            return Obj;
          case 'dept-room':
            Reflect.set(Obj, 'fontSize', pxToVw(info.roomNameFontSize));
            return Obj;
        }
      }
    },

    optionScroll() {
      let {openScroll, waitPatientStep} = (this.optionsInfo)
      return {
        hoverStop: true,
        direction: 1,                               // 0向下 1向上 2向左 3向右
        openTouch: false,
        step: [1, 1.5, 2, 2.5, 3][waitPatientStep - 1], // 数值越大速度滚动越快
        limitMoveNum: openScroll ? 4 : 999999, // 开始无缝滚动的数据量 this.dataList.length
      };
    },

    optionScroll2() {
      let {waitPatientStep} = (this.optionsInfo)
      return {
        hoverStop: true,
        direction: 1,
        // 0向下 1向上 2向左 3向右
        isSingleRemUnit: true,
        openTouch: false,
        step: [1, 1.5, 2, 2.5, 3][waitPatientStep - 1], // 数值越大速度滚动越快
        limitMoveNum: 2, // 开始无缝滚动的数据量 this.dataList.length
      };
    },

    doctorDataClean() {
      return this.$lodash.chunk(this.doctorData, 1)
    },

    // 获取科室&诊室信息
    getRoomDeptInfo() {
      let devType = (this.devType);
      let roomDoctorInfo = this.$store.getters['getRoomDeptInfo'];
      if (devType) {
        return roomDoctorInfo.apiData;
      } else {
        return roomDoctorInfo.mockData;
      }
    },

    //顶部科室和诊室的claasName
    getClassName() {
      let {defaultShowCol = ['deptName', 'roomName']} = this.optionsInfo;
      let length = defaultShowCol?.length;
      switch (length) {
        case 1:
          return 'dept-room-1'
        case 2:
          return 'dept-room-default'
      }
    },

    //顶部科室诊室显示控制
    deptRoomshow() {
      return function (row) {
        let {defaultShowCol = ['deptName', 'roomName']} = this.optionsInfo;
        return defaultShowCol.includes(row)
      }
    },

    // 判断候诊模式
    waitPatientTypeInfo() {
      let {waitPatientType = 1} = this.optionsInfo;
      return waitPatientType
    },

    // 判断当前患者是否滚动
    scrollInfo() {
      return function (info) {
        return !!(info.treatingPatient) && (info.treatingPatient.length) > 1
      }
    },

    // 判断过号患者是否滚动
    scrollInfoOver() {
      return function (info) {
        return !!(info.overPatientList) && (info.overPatientList.length) > 2
      }
    },

    // 候诊患者截取
    getWaitingPatientList() {
      return function (row) {
        let {waitPatientType=1, waitMode, waitPatientNumber} = (this.optionsInfo);
        switch (waitPatientType) {
          case 1:
            return !!(row?.length) ? row.slice(0, waitMode) : []
          case 2:
            return !!(row?.length) ? row.slice(0, waitPatientNumber) : []
        }
      }
    },

    // 诊室等待--设置不同模式下的等待患者样式
    getPatientClassName() {
      let {waitMode, waitingPatientHide} = (this.optionsInfo);
      return function (type, row) {
        if (!waitingPatientHide) {
          switch (type) {
            case 'pass-patient':
              return parseInt(waitMode) !== 1 ? 'pass-patient' : 'pass-patient2'
            case 'current-patient':
              return parseInt(waitMode) !== 1 ? 'current-patient' : 'current-patient2'
            case 'wait-patient':
              switch (waitMode) {
                case 1:
                  return 'wait-patient'
                case 2:
                  return 'wait-patient2'
                case 3:
                  return 'wait-patient3'
                case 4:
                  return 'wait-patient4'
              }
          }
        } else {
          return 'hide-waiting-patient'
        }
      }
    },

    // 候诊等待
    getWaitPatientNumber() {
      return function (row, scroll) {
        let waitingPatientList = this.getWaitingPatientList(row);
        if (scroll) {
          if (Array.isArray(waitingPatientList)) {
            return `scroll-area-${waitingPatientList.length}`
          } else {
            return `scroll-area`
          }
        } else {
          if (Array.isArray(waitingPatientList)) {
            if (waitingPatientList.length >= 4) {
              return `no-scroll-area-4`
            } else {
              return `no-scroll-area-${waitingPatientList.length}`
            }
          } else {
            return `no-scroll-area`
          }
        }
      }
    },

    // 是否暂停
    getDoctorState() {
      return function (row) {
        return !!(row?.isPause)
      }
    },

    // 获取医生头像
    getDoctorPicture() {
      return function (row) {
        let isPause = (row?.isPause);
        let header = '/tpleditor/resource/assets/images/header.png';
        if (!isPause) {
          return (row.workerPicture) || header
        } else {
          return this.pause;
        }
      }
    },

  },

  mounted() {},

  methods: {
    handleError(event) {
      event.target.src = '/tpleditor/resource/assets/images/header.png'
    },

    // 滚动结束
    handleScrollEnd() {
      console.log('滚动结束')
    },
  },

  watch: {
    field: {
      handler: function (val) {
        let key = (val.options.config)
        this.optionsInfo = val.options[key];
      },
      deep: true,
      immediate: true
    }
  }

};
</script>

<style lang="scss" scoped>
.trends3-doctor-list-2 {
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  overflow: hidden;

  .queue-info{
    height: 50%;
    overflow: hidden;
    &:first-child{
      padding-top: 20px;
      box-sizing: border-box;
    }
    &:last-child{
      padding-top: 10px;
      box-sizing: border-box;
    }
  }

  .dept-room-default {
    padding: 10px 0 10px 0;
    box-sizing: border-box;
    background: #0059B3;
    width: 100%;
    overflow: hidden;
    flex-shrink: 0;
    height: 170px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    align-self: center;
    color: #FFFFFF;
    font-size: 60px;

    p {
      color: #FFFFFF;
      font-size: 60px;
      font-weight: 500;
      text-align: center;
      @include singleEllipsis(100%);
    }

    .dept {
      font-size: 60px;
      line-height: 1.35;
      @include singleEllipsis(100%);
    }

    .room {
      font-size: 60px;
      line-height: 1.35;
      padding: 0 18px 0 18px;
      @include singleEllipsis(100%);
    }

    .wrap-text {
      white-space: normal;
      width: 100%;
      font-size: 60px;
      .line {
        display: block;
        @include singleEllipsis(100%);
        font-weight: 500;
        font-size: 60px;
        text-align: center;
      }
    }
  }

  //科室||诊室
  .dept-room-1 {
    display: flex;
    align-items: center;
    align-self: center;

    .room {
      font-size: 134px;
      line-height: 1.35;
    }
  }

  .first-group {
    display: flex;
    flex-direction: row;
    flex-shrink: 0;
    flex-grow: 1;
    box-sizing: border-box;
    overflow: hidden;
    margin-top: 24px;
    height: calc(100% - 170px - 24px - 20px);
    .left {
      width: 280px;
      height: 100%;
      box-sizing: border-box;
      margin-right: 18px;
      flex-shrink: 0;
      background: white;
      border-radius: 16px;
      overflow: hidden;

      .left-img {
        height: 420px;
        overflow: hidden;
        img {
          width: 100%;
          height: calc(100%);
          object-fit: cover;
        }
      }

      .doc-area {
        height: calc(100% - 420px);
        position: relative;
        .name {
          font-size: 52px;
          line-height: 1.4;
          color: #003f76;
          padding: 6px 18px 0 18px;
          box-sizing: border-box;
        }

        .academic—title {
          font-size: 38px;
          line-height: 1.5;
          background-color: #0059B3;
          color: white;
          border-radius: 8px;
          box-sizing: border-box;
          padding: 0 10px;
          max-width: calc(100% - 20px);
          margin: 6px auto 0 auto;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }

    .right {
      width: calc(100% - 280px - 20px);
      display: flex;
      flex-direction: column;

      .patient-wrap {
        display: flex;
        overflow: hidden;
        flex-direction: column;
        border-radius: 18px;

        .item {
          display: flex;
          overflow: hidden;
          border-radius: 20px;

          .title {
            color: white;
            align-items: center;
            align-self: center;
            text-align: center;
            height: 100%;
            line-height: 1.15;
            padding: 0 20px;
            flex: inherit;
            display: flex;
            width: 100px !important;
            font-size: 40px;
          }

          .content {
            display: flex;
            flex-direction: column;
            align-self: center;
            align-items: center;
            justify-content: left;
            background: transparent;
            border: none;
            overflow: hidden;
            border-radius: 18px;

            width: calc(100% - 100px) !important;

            p {
              font-size: 80px;
              width: 100%;
              line-height: 126px;
              text-align: left;
              padding-left: 60px;
              @include singleEllipsis(100%)
            }

            :deep(.scroll) {
              width: 100%;
              min-height: 150px;
              overflow: hidden;

              .inside-content {
                height: 100%;
                display: flex;
                flex-direction: row;
                flex-wrap: wrap;
                align-self: center;
                align-items: center;
                overflow: hidden;

                .patient {
                  height: auto;
                  flex-basis: 50%;
                  min-width: 50%;
                  box-sizing: border-box;
                  overflow: hidden;
                  font-size: 60px;
                  line-height: 120px;
                  text-align: left;
                  padding-left: 30px;
                  color: rgba(229, 134, 2, 1);
                  @include singleEllipsis(100%);
                  .patient-orderNo {
                    padding-right: 4px;
                  }
                }
              }

              .scroll-area-1-1 {
                display: flex;
                width: 100%;
                height: 100%;
                flex-wrap: wrap;
                align-self: center;
                align-items: center;
                flex-direction: column;

                .patient {
                  flex-basis: 100%;
                  min-width: 100%;
                  font-size: 40px !important;
                  text-align: center;
                  box-sizing: border-box;
                  padding-left: 56px;
                  line-height: 100px !important;
                  color: rgba(229, 134, 2, 1) !important;
                  @include singleEllipsis(100%);
                }
              }

              .scroll-area-2-2 {
                display: flex;
                width: 100%;
                height: 100%;
                flex-wrap: wrap;
                align-self: center;
                align-items: center;
                flex-direction: column;

                .patient {
                  flex-basis: 100%;
                  min-width: 100%;
                  font-size: 46px !important;
                  text-align: center;
                  box-sizing: border-box;
                  line-height: 100px !important;
                  color: rgba(229, 134, 2, 1) !important;
                  @include singleEllipsis(100%);
                }
              }
            }

            :deep(.scroll2) {
              width: 100%;
              min-height: 180px;
              overflow: hidden;

              .inside-content {
                height: 100%;
                display: flex;
                flex-direction: row;
                flex-wrap: wrap;
                align-self: center;
                align-items: center;
                overflow: hidden;
                color: #727C82;
                .patient {
                  height: auto;
                  flex-basis: 50%;
                  min-width: 50%;
                  box-sizing: border-box;
                  overflow: hidden;
                  font-size: 60px;
                  line-height: 120px;
                  text-align: left;
                  padding-left: 30px;
                  @include singleEllipsis(100%);

                  .patient-orderNo {
                    padding-right: 4px;
                  }
                }
              }

              .scroll-area-1-1 {
                display: flex;
                width: 100%;
                height: 100%;
                flex-wrap: wrap;
                align-self: center;
                align-items: center;
                flex-direction: column;

                .patient {
                  flex-basis: 100%;
                  min-width: 100%;
                  font-size: 80px !important;
                  text-align: center;
                  box-sizing: border-box;
                  padding-left: 56px;
                  line-height: 100px !important;
                  color: rgba(229, 134, 2, 1);
                  @include singleEllipsis(100%);
                }
              }

              .scroll-area-2-2 {
                display: flex;
                width: 100%;
                height: 100%;
                flex-wrap: wrap;
                align-self: center;
                align-items: center;
                flex-direction: column;

                .patient {
                  flex-basis: 100%;
                  min-width: 100%;
                  text-align: center;
                  box-sizing: border-box;
                  font-size: 80px !important;
                  line-height: 100px !important;
                  color: rgba(229, 134, 2, 1);
                  @include singleEllipsis(100%);
                }
              }
            }

            .no-scroll-area-1 {
              display: flex;
              width: 100%;
              flex-wrap: wrap;
              flex-direction: column;

              p {
                flex-basis: 100%;
                min-width: 100%;
                font-size: 66px !important;
                text-align: left;
                box-sizing: border-box;
                padding-left: 60px;
                line-height: 86px !important;
              }
            }

            .no-scroll-area-2 {
              display: flex;
              flex-wrap: wrap;
              flex-direction: column;
              width: 100%;

              p {
                flex-basis: 100%;
                min-width: 100%;
                font-size: 50px !important;
                text-align: left;
                box-sizing: border-box;
                padding-left: 60px;
                line-height: 86px !important;
              }
            }

            .no-scroll-area-3,
            .no-scroll-area-4 {
              display: flex;
              flex-wrap: wrap;
              align-items: center;

              p {
                flex-basis: 50%;
                min-width: 50%;
                font-size: 46px !important;
                text-align: left;
                box-sizing: border-box;
                padding-left: 30px;
                line-height: 86px !important;
              }
            }

          }

          .current-patient-info {
            height: 100%;
            display: flex;
            align-self: center;
            align-items: center;

            .scroll-info {
              width: 100%;
              overflow: hidden;
              margin-top: 20px;
              height: calc(100%);
              box-sizing: border-box;

              p {
                height: 100%;
                width: 100%;
                display: flex;
                font-size: 70px;
                line-height: 120px;
                align-items: flex-start;
                @include singleEllipsis(100%)
              }
            }
          }

          .scroll-area-all {
            align-items: start;
            align-self: auto;
          }
        }

        .current-patient {
          height: 164px;
          background: rgba(0, 89, 179, 0.2);

          .title {
            font-size: 50px;
            background: rgba(0, 89, 179, 1);
          }

          p {
            color: rgba(0, 89, 179, 1);
            font-size: 66px !important;
            @include singleEllipsis(100%);
          }
        }

        .current-patient2 {
          height: 164px;
          min-width: auto;

          .title {
            font-size: 50px;
          }
        }

        .flex-box {
          min-height: 180px;
        }
        .wait-patient {
          height: 144px;
          margin-top: 20px;
          min-width: auto;
          background: rgba(255, 198, 85, 0.2);

          .title {
            font-size: 50px;
            background: rgba(229, 134, 2, 1);
          }

          p {
            color: rgba(229, 134, 2, 1);
            line-height: 186px !important;
            font-size: 66px !important;
          }
        }

        .wait-patient2 {
          height: 164px;

          p {
            line-height: 70px !important;
            font-size: 50px !important;
          }

        }

        .wait-patient3 {
          height: 164px;

          .content {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;

            p {
              flex-basis: 50%;
              min-width: 50%;
              font-size: 46px !important;
              text-align: left;
              padding-left: 30px;
              line-height: 86px !important;
              @include singleEllipsis(100%)
            }
          }
        }

        .wait-patient4 {
          height: 164px;

          .content {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;

            p {
              flex-basis: 50%;
              min-width: 50%;
              font-size: 46px !important;
              text-align: left;
              padding-left: 30px;
              line-height: 86px !important;
              @include singleEllipsis(100%)
            }
          }


        }

        .pass-patient {
          height: 216px;
          margin-top: 24px;
          background: #BFCBD2;
          min-width: auto;

          .title {
            font-size: 50px;
            background: #6D767C;
          }

          .content {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            color: #727C82;
            p {
              flex-basis: 100%;
              min-width: 100%;
              font-size: 46px !important;
              text-align: left;
              padding-left: 50px;
              @include singleEllipsis(100%)
            }
          }

        }

        .pass-patient2 {
          height: 164px;
          min-width: auto;

          .title {
            font-size: 50px;
          }
        }

      }

      :deep(.no-scroll-info2) {
        display: flex;
        width: 100%;
        overflow: hidden;
        div {
          flex-basis: calc(100% / 2);
          min-width: calc(100% / 2);
          font-size: 60px;
          flex-shrink: 0;
          line-height: 1.5;
          box-sizing: border-box;
          justify-content: center;
          align-items: start;
          text-align: left;
          padding-left: 60px;
          @include singleEllipsis(100%);
        }
      }

    }
  }
}
</style>
